****************************************************************************
* File-Nale: 		tess.do
* Date:		 04/30/2018
* Author: 		Fred Batista
* Purpose: 		Analysis of TESS experiment data
* Data used: 		tess.dta
* Data Output:	Journal of Politics� paper	*/
****************************************************************************

* RECODING CONTROL VARIABLES

* party id

gen partyid = (XPARTY7-1)/6

label variable partyid "Party Identification 7-point scale recoded from 0 to 1"

* ideology

recode xideo (-1=.)

gen ideology = (xideo-1)/ 6

label variable ideology "Ideology 7-point scale recoded from 0 to 1"

* age

gen age = (ppage-18)/(92 - 18)

label variable age "Age recode from 0 to 1"

* education

gen education = (ppeduc - 3)/11

label variable education "Years of Education recoded form 0 to 1"

* income

gen income = (ppincimp - 1)/18

label variable income "Income recoded from 0 to 1"

* head of household

gen hhhead = pphhhead

label variable hhhead "Respondent is the head of the household"

* religact

recode XREL2 (-1=.)

gen religact = (6-XREL2)/5

label variable religact "Religios Activity Attendance recode from 0 to 1"

* single

gen single = ppmarit

recode single (5=1) (else=0)

label variable single "Respondent is single"

* employed

gen employed = ppwork

recode employed (1 2=1) (else=0)

label variable employed "Respondent is employed"

* race

gen black = ppethm

recode black (2=1) (else=0)

label variable black "Race=black"

gen white = ppethm

recode white (1=1) (else=0)

label variable white "Race=white"

* children

gen children = PPT01 + PPT25 + PPT612 + PPT1317

recode children (0=0) (else=1)

label variable children "Respondent has children"

* household with internet access

gen internet = ppnet

label variable internet "Household with internet access"

* south

gen south = ppstaten

recode south (51 52 54 55 56 57 58 59 61 62 63 64 71 72 73 74=1) (else=0)

label variable south "Respondent is from the South"

* duration

replace duration =. if duration > 60

replace duration =. if duration < 1

replace duration = (duration - 1)/58

gen duration_sq = duration*duration

label variable duration_sq "Duration squared"


* RECODING TREATMENT

gen condition = XTESS160

label define conditionl 1 "All-Male Thermometers (Threat)" 2 "Mixed Thermometers (Lift)" 3 "No Thermometers (Baseline)"

label values condition conditionl

tab condition, gen(cond)

gen no_therm = cond3

gen allmale_therm = cond1

gen mixed_therm = cond2

drop cond1 cond2 cond3

label variable no_therm "No thermometers condition"

label variable allmale_therm "All-male thermometers condition"

label variable mixed_therm "Mixed thermometers condition"

* RECODING GENDER

gen male = 2 - ppgender

label variable male "Male respondent"

* RECODING MANIPULATION CHECK VARIABLE

* as continuous

gen womensupreme = Q12

recode womensupreme (-1=.)

label variable womensupreme "Number of women in supreme court"


* as nominal variable (0 unerstimate, 1 correct, 2 overestimate)

gen courtestimate = Q12

recode courtestimate (3=1) (0 1 2=0) (4 5 6 7 8 9=2) (-1=.)

label define celabel 0 "Underestimate" 1 "Correct" 2 "Overestimate"

label values courtestimate celabel

label variable courtestimate "Court estimate nominal"



* RECODES AND CONSTRUCTION OF KNOWLEDGE QUESTIONS

gen Q6recode = Q6
recode Q6recode (-1=9) (6=1) (else=0)
label variable Q6recode "recode of Q6)

gen senateterm = Q6recode
recode senateterm (9 0=0) (1=1)

gen billrights = Q7recode
recode billrights (9 0 = 0) (1=1)

gen boehner = Q8recode
recode boehner (9 0 = 0) (1=1)

gen putin = Q9recode
recode putin (9 0 = 0) (1=1)

gen majority = Q10recode
recode majority (9 0 = 0) (1=1)

gen supreme = Q11recode
recode supreme (9 0 = 0) (1=1)

alpha senateterm billrights boehner putin majority supreme

factor senateterm billrights boehner putin majority supreme, factor(1) ml

predict knowledge_factor

summarize knowledge_factor

replace knowledge_factor = (knowledge_factor - r(min))/(r(max) - r(min))

gen knowledge = (senateterm + billrights + boehner + putin + majority + supreme)/6

label variable knowledge "Additive scale of knowledge from 0 to 1"

* summarizing variables

summarize male knowledge education income white religact single duration


*BALANCE CHECKS (across conditions: only religiosity; between men and women across conditions: education, income, black, religiosity, single)

mlogit condition male education age income black religact single children employed hhhead partyid ideology internet south [pweight=weight], base(2)


by condition: reg education male [pweight=weight]

by condition: reg age male [pweight=weight]

by condition: reg income male [pweight=weight]

by condition: logit black male [pweight=weight]

by condition: reg religact male [pweight=weight]

by condition: logit single male [pweight=weight]

by condition: logit children male [pweight=weight]

by condition: logit employed male [pweight=weight]

by condition: logit hhhead male [pweight=weight]

by condition: logit internet male [pweight=weight]

by condition: reg partyid male [pweight=weight]

by condition: reg ideology male [pweight=weight]

by condition: logit south male [pweight=weight]


*** MAIN ANALYSIS

sort condition

by condition: reg knowledge male education income white religact single duration duration_sq [pweight=weight]

by condition: reg knowledge male [pweight=weight]


** separated by condition in order to obtain predicted values

* no thermometers

reg knowledge male education income white religact single duration duration_sq[pweight=weight] if condition==3

eststo

margins, at(male=0)

margins, at(male=1)

* all-male thermometers

reg knowledge male education income white religact single duration duration_sq[pweight=weight] if condition==1

eststo

margins, at(male=0)

margins, at(male=1)

* mixed thermometers

reg knowledge male education income white religact single duration duration_sq[pweight=weight] if condition==2

eststo

margins, at(male=0)

margins, at(male=1)

*** interaction

reg knowledge i.male##i.allmale_therm i.male##i.mixed_therm  education income white religact single duration duration_sq [pweight=weight]

*** interaction without controls

reg knowledge i.male##i.allmale_therm i.male##i.mixed_therm  [pweight=weight]


* generating table of results

estout, style(tex) cells(b(star fmt(2)) se(fmt(2) par)) stats(r2 n) starlevels(* 0.05)


* use Table to display overall results 
* creating a figure with the results by gender

matrix predict2 = (.5844744\.445821\.5395055\.4390076 \.557677\.5109257) 

matrix lower2 = (.5350367 \.4018588\.4806189\.3921483\.5075063\.4540055)

matrix upper2 = (.6339122\ .4897833\.5983921\.4858668\.6078477\.567846)

matrix gender2 = (1\2\1\2\1\2)

matrix condition2 = (1\1\2\2\3\3)

matrix figure2 = predict2, lower2, upper2, gender2, condition2

matrix list figure2

svmat figure2, name(c)

eclplot c1 c2 c3 c5, horizontal supby(c4, spaceby(0.1) offset(-.05)) ciopts(blcolor(black) msize(vtiny)) estopts1(color(black)) estopts2(color(black) m(circle_hollow) mfcolor(white)) xtitle("") ylabel(.8 " " 1 `" "{stSans:No         }" "{stSans:Thermometers}" "' 2 `" "{stSans:All-Male     }" "{stSans:Thermometers}" "' 3 `" "{stSans:Mixed       }" "{stSans:Thermometers}" "' 3.2 " ", noticks labgap(2) nogrid) yticks(1 2 3, tl(2)) xlabel(.35 "{stSans:0.35}" .40 "{stSans:0.40}" .45 "{stSans:0.45}" .50 "{stSans:0.50}" .55 "{stSans:0.55}" .60 "{stSans:0.60}" .65 "{stSans:0.65}" .70 "{stSans:0.70}", tl(2) nogrid) ytitle("") legend(region(lcolor(white)) pos(4) ring(0) col(1) order(2 "{stSans:Male}" 4 "{stSans:Female}") size(small)) ysize(10) xsize(10) plotregion(ls(none)) graphregion(color(white)) xscale(noextend) yscale(noextend) name(TESSresults_h)

graph export TESSresults_h.pdf


* MANIPULATION CHECK (EFFECTS ON ESTIMATION OF WOMEN IN SUPREME COURT)

* main model (mlogit) for all sample

mlogit courtestimate allmale_therm mixed_therm male education income white religact single duration duration_sq [pweight=weight], base(1)

prvalue, x(allmale_therm=0 mixed_therm=0) rest(mean)

prvalue, x(allmale_therm=1 mixed_therm=0) rest(mean)

prvalue, x(allmale_therm=0 mixed_therm=1) rest(mean)


* by gender

mlogit courtestimate allmale_therm mixed_therm education income white religiosity single duration duration_sq [pweight=weight] if male==1, base(1)

prvalue, x(allmale_therm=0 mixed_therm=0) rest(mean)

prvalue, x(allmale_therm=1 mixed_therm=0) rest(mean)

prvalue, x(allmale_therm=0 mixed_therm=1) rest(mean)

mlogit courtestimate allmale_therm mixed_therm education income white religiosity single duration duration_sq [pweight=weight] if male==0, base(1)

prvalue, x(allmale_therm=0 mixed_therm=0) rest(mean)

prvalue, x(allmale_therm=1 mixed_therm=0) rest(mean)

prvalue, x(allmale_therm=0 mixed_therm=1) rest(mean)

** cross tab

* with DK

gen courtestimate2 = Q12
recode courtestimate2 (3=1) (0 1 2=0) (4 5 6 7 8 9=2) (-1=3)

label define celabel2 0 "Underestimate" 1 "Correct" 2 "Overestimate" 3 "Don't Know"

label values courtestimate2 celabel2

tab courtestimate2 condition [aweight=weight], col nof

mlogit courtestimate2 allmale_therm mixed_therm male education income white religact single duration duration_sq [pweight=weight], base(1)


* without DK

tab courtestimate condition [aweight=weight] if duration!=., col nof

tab courtestimate condition [aweight=weight] if duration!=. & male==0, col nof

tab courtestimate condition [aweight=weight] if duration!=. & male==1 , col nof


* ANALYSES OF DKs

* creating respondent-item dataset

sort CaseID

expand 2, gen(dupli1)

expandcl 3, gen(dupli2) cluster(dupli1)

sort dupli2 CaseID

gen DKvar =.

replace DKvar = Q6recode if dupli2==1

replace DKvar = Q7recode if dupli2==2

replace DKvar = Q8recode if dupli2==3

replace DKvar = Q9recode if dupli2==4

replace DKvar = Q10recode if dupli2==5

replace DKvar = Q11recode if dupli2==6

tab dupli2, gen(item)

sort condition

by condition: mlogit DKvar male education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight], base(1) cluster(CaseID)

mlogit DKvar male education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight] if condition==1, base(1) cluster(CaseID)

margins, at(male=0)

margins, at(male=1)

mlogit DKvar male education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight] if condition==2, base(1) cluster(CaseID)

margins, at(male=0)

margins, at(male=1)

mlogit DKvar male education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight] if condition==3, base(1) cluster(CaseID)

margins, at(male=0)

margins, at(male=1)


* graph with all results and condition as independent var.

mlogit DKvar male education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight] if condition==1, base(1) cluster(CaseID)

margins, dydx(male) predict(outcome(9))

margins, dydx(male) predict(outcome(0))

margins, dydx(male) predict(outcome(1))

mlogit DKvar male education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight] if condition==2, base(1) cluster(CaseID)

margins, dydx(male) predict(outcome(9))

margins, dydx(male) predict(outcome(0))

margins, dydx(male) predict(outcome(1))

mlogit DKvar male education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight] if condition==3, base(1) cluster(CaseID)

margins, dydx(male) predict(outcome(9))

margins, dydx(male) predict(outcome(0))

margins, dydx(male) predict(outcome(1))


matrix predictALL = (-.1145322\-.0218227\.1363549\-.08689\-.0133768\.1002668\-.0406378\-.0101617\.0507995)

matrix lowerALL = (-.1675283\ -.0675913\.0749458\-.168469\-.0623343\.0253578\-.112947\-.055247\-.0258412)

matrix upperALL = ( -.061536\.0239459\.1977639\-0.0039\0.0337\0.1749\.0316713\.0349237\.1274401)

matrix responseALL = (-1\0\1\-1\0\1\-1\0\1)

matrix conditionALL = (1\1\1\2\2\2\3\3\3)

matrix figureALL = predictALL, lowerALL, upperALL, responseALL, conditionALL

matrix list figureALL

svmat figureALL, name(j)

eclplot j1 j2 j3 j5, supby(j4, spaceby(0.1) offset(-0.1)) horizontal xline(0, lcolor(black) lp(dash)) ciopts(blcolor(black) msize(vtiny)) estopts1(color(black) m(circle_hollow)) estopts2(color(black) m(X) mfcolor(white) msize(large)) estopts3(color(black)) ylabel(0.3 " " 1 `" "{stSans:No         }" "{stSans:Thermometers}" "' 2 `" "{stSans:All-Male     }" "{stSans:Thermometers}" "' 3 `" "{stSans:Mixed       }" "{stSans:Thermometers}" "' 3.3 " ", noticks labgap(2) tl(2) nogrid) ytick(1 2 3) ytitle("") xtitle("") xlabel(-.20 "{stSans:-0.20}" -.10 "{stSans:-0.10}" 0 "{stSans:0}" .10 "{stSans:0.10}" .20 "{stSans:0.20}") legend(region(lcolor(white)) pos(1) ring(0) c(1) order(2 "{stSans:Don't Know}" 4 "{stSans:Incorrect}" 6 "{stSans:Correct}") size(small)) ysize(10) xsize(8) graphregion(color(white)) plotregion(style(none)) xscale(noextend) yscale(noextend) name(DKgraph2)

graph export DKgraph2.pdf


* main model in DK dataset without controls

by condition: mlogit DKvar male item2 item3 item4 item5 item6 [pweight=weight], base(1) cluster(CaseID)


* interaction for DK dataset

mlogit DKvar i.male##i.allmale_therm i.male##i.mixed_therm education income white religact single duration duration_sq item2 item3 item4 item5 item6 [pweight=weight], base(1) cluster(CaseID)

* without controls

mlogit DKvar i.male##i.allmale_therm i.male##i.mixed_therm item2 item3 item4 item5 item6 [pweight=weight], base(1) cluster(CaseID)


*** ADDITIONAL	

* power analysis

*power twomeans .139 .101, sd(.33) n(100(100)1000) graph

power twomeans .139 .047, sd(.33) n(100(100)1000) graph

power twomeans .101 .047, sd(.33) n(100(100)1000) graph

power twomeans .101 .047, sd(.33) n(647)
